#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t id = fork();
    if(id == 0){ 
        printf("我是一个子进程，pid: %d, ppid:%d\n", getpid(), getppid());
        printf("子进程开始替换\n");
        sleep(5);
        execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
        printf("替换失败\n");
        exit(1);
    }
    //father
    sleep(2);
    printf("父进程开始等待子进程\n");
    pid_t ret = waitpid(id, NULL, 0);
    if(ret > 0) printf("wait success, father pid: %d, ret id: %d\n", getpid(), ret);

    sleep(5);
    return 0;
}
